<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <h1>微博详情页面</h1>
  <h2>{{weibo.nickname}}说:{{weibo.content}}</h2>
  <span>{{weibo.created}}</span>
  <img v-for="url in weibo.urls.split(',')" :src="url" width="100px" alt="">
    <hr>
    <div v-for="c in arr">
        {{c.nickname}}评论说:{{c.content}}
    </div>

    <input type="text" v-model="comment.content">
    <input type="button" value="发表评论" @click="f()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
          weibo:{},
            comment:{content:""},
            arr:[]
         },
        methods: {
            f(){
                //设置原微博的id
                v.comment.weiboId = v.weibo.id;
                axios.post("/comment/insert",v.comment).then(function (response) {
                    if (response.data==1){
                        location.reload();
                    }else{
                        alert("请先登录!");
                        location.href="/login.html";
                    }
                })
            }
        },
      created:function () {
        axios.get("/weibo/selectById"+location.search).then(function (response) {
          v.weibo = response.data;
        })

          axios.get("/comment/selectByWeiboId"+location.search).then(function (response) {
              v.arr = response.data;
          })

      }
    })
</script>
</body>
</html>